package com.manager.car.service;

import java.util.List;

import com.manager.car.dao.IManagerInfoDao;
import com.manager.car.po.ManagerInfo;
import com.manager.car.util.PageModel;




public class ManagerInfoServiceImpl implements IManagerInfoService {

	private IManagerInfoDao managerInfoDao;
	
	//定义方法实现登录页面登录功能
	public boolean getQueryListByHql(ManagerInfo manager) {
		boolean bool = false;
		List<ManagerInfo> list = managerInfoDao.getQueryListByHql("from ManagerInfo where managerName = '"+manager.getManagerName()+"' and  managerPassword = '"+manager.getManagerPassword()+"'");
		
		if(list==null||list.size()<0) {
			bool = false;
		}else {
			for(ManagerInfo mi : list) {
				if(mi.getManagerStatic()==1) {
					bool = false;
				}else {
					mi.setManagerStatic(1);
					bool = managerInfoDao.update(mi);
					System.out.println(bool);
				}
			}
		}
		return bool;
	}
	
	public PageModel<ManagerInfo> queryPageModelByHql(int pageNo, int pageSize) {
		String hql = "from ManagerInfo order by managerId desc";
		
		PageModel<ManagerInfo> model = managerInfoDao.queryPageModelByHql(pageNo, pageSize, hql);
				
		return model;
	}

	public boolean deleteManagerInfoById(Integer id) {
		boolean bool = managerInfoDao.delete(id);
		return bool;
	}

	public boolean updateManagerInfoStaticById(Integer id) {
		boolean bool = managerInfoDao.updataManagerInfoStaticById(id);
		return bool;
	}

	public boolean addManager(ManagerInfo mi) {
		boolean bool = managerInfoDao.save(mi);
		return bool;
	}

	public boolean updateManager(ManagerInfo mi) {
		boolean bool = managerInfoDao.update(mi);
		return bool;
	}

	public ManagerInfo queryManagerInfoById(Integer Id) {
		
		ManagerInfo mi =  managerInfoDao.getElement(Id);
		
		return mi;
	}

	public IManagerInfoDao getManagerInfoDao() {
		return managerInfoDao;
	}

	public void setManagerInfoDao(IManagerInfoDao managerInfoDao) {
		this.managerInfoDao = managerInfoDao;
	}
	
	

}
